import da from 'element-ui/src/locale/lang/da'
import {zhou_for_admin} from '../data'

const STATE = {
  0: {
    type: 'primary',
    text: '出勤'
  },
  1: {
    type: 'warning',
    text: '迟到'
  },
  2: {
    type: 'danger',
    text: '缺勤'
  },
  3: {
    type: 'success',
    text: '请假'
  }
}
export default {
  get_courses_info (state, {data}){
    state.courses_teach_by_someone = data
  },
  get_class_member (state, {data}) {
    state.students = data
  },
  clear_students (state) {
    state.students = []
    state.students_with_call_info = []
  },
  prepare_call_info (state, {data}) {
    state.students_with_call_info = data
  },
  change_state_of_call_info(state, {index, s}) {
    const call_info = state.students_with_call_info
    call_info[index].s = STATE[s]
    state.students_with_call_info = call_info
  },
  change_state_of_call_info_by_z_t_j(state, {value}) {
    const call_info = state.students_with_call_info
    call_info.z_t_j = value
    state.students_with_call_info = call_info
  },
  set_record_class(state, {class_id}){
    state.sel_class = class_id
  },
  clear_some_data(state) {
    state.sel_class = undefined
    state.sel_course = undefined
    state.students_with_call_info = []
    state.students = []
  },
  set_record_course(state, {course_id}) {
    state.sel_course = course_id
  },
  set_called_info(state, {d}) {
    const before_student_with_call_info = state.students_with_call_info
    d.z_t_j = before_student_with_call_info.z_t_j
    state.students_with_call_info = d
  },
  set_statistics_z_t(state, {data}){
    state.statistics_z_t.data = data
  },
  set_call_data(state, {data}) {
    console.log(data)
    switch (state.statistics_now_state) {
      case 0:
        data.forEach((d) => {
          d.all_number = d.department_all_number
          d.at_number = d.department_at_number
          d.rate = d.f_rate
          d.no_at_number = d.department_no_at_number
          d.name = d.department_name
        })
        state.statistics_data = data
        break
      case 1:
        data.forEach((d) => {
          d.all_number = d.major_all_number
          d.at_number = d.majort_at_number
          d.rate = d.m_rate
          d.no_at_number = d.major_no_at_number
          d.name = d.major_name
        })
        state.statistics_data = data
        break
      case 2:
        data.forEach((d) => {
          d.all_number = d.grade_all_number
          d.at_number = d.grade_at_number
          d.rate = d.g_rate
          d.no_at_number = d.grade_no_at_number
          d.name = d.grade_name
        })
        state.statistics_data = data
        break
    }

  },
  change_statistics_now_state(state) {
    state.statistics_now_state = (state.statistics_now_state + 1) % 4
  },
  clear_statistics(state, {clear_something}) {
    if(clear_something.includes("statistics_data")){
      state.statistics_data = []
    }
    if(clear_something.includes("statistics_now_state")) {
      state.statistics_now_state = 0
    }
    if(clear_something.includes("statistics_z_t")){
      state.statistics_z_t = []
    }
  },
  set_see_options (state, {zhou_for_admin}) {
    state.z_t_j_see = zhou_for_admin
  },
  clear_see(state, {clear_something}) {
    if(clear_something.includes("z_t_j_see")) {
      state.z_t_j_see = []
    }
    if(clear_something.includes("z_t_j_value_see")) {
      state.z_t_j_value_see.data = []
    }
  },
  set_today_calls(state, {data}) {
    state.today_calls = data
    const subjects = []
    data[0].course.forEach((v)=>{
      subjects.push(v.course_name)
    })
    state.subjects = subjects
  }
}
